<?php

/**
 * This is the model class for table "tbl_installations".
 *
 * The followings are the available columns in table 'tbl_installations':
 * @property string $id
 * @property string $requested
 * @property integer $assigned
 * @property integer $finished
 * @property string $note
 * @property string $tbl_service_group_id
 * @property string $tbl_client_id
 *
 * The followings are the available model relations:
 * @property TblServiceGroup $tblServiceGroup
 * @property TblClient $tblClient
 */
class Installations extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Installations the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_installations';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('tbl_service_group_id, tbl_client_id', 'required'),
			array('assigned, finished', 'numerical', 'integerOnly'=>true),
			array('tbl_service_group_id', 'length', 'max'=>10),
			array('tbl_client_id', 'length', 'max'=>20),
			array('requested, note', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, requested, assigned, finished, note, tbl_service_group_id, tbl_client_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'tblServiceGroup' => array(self::BELONGS_TO, 'TblServiceGroup', 'tbl_service_group_id'),
			'tblClient' => array(self::BELONGS_TO, 'TblClient', 'tbl_client_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'requested' => 'Requested',
			'assigned' => 'Assigned',
			'finished' => 'Finished',
			'note' => 'Note',
			'tbl_service_group_id' => 'Tbl Service Group',
			'tbl_client_id' => 'Tbl Client',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('requested',$this->requested,true);
		$criteria->compare('assigned',$this->assigned);
		$criteria->compare('finished',$this->finished);
		$criteria->compare('note',$this->note,true);
		$criteria->compare('tbl_service_group_id',$this->tbl_service_group_id,true);
		$criteria->compare('tbl_client_id',$this->tbl_client_id,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}